#pragma once
#include <drogon/HttpController.h>
#include <git2.h>
#include <string>

class GitManager : public drogon::HttpController<GitManager> {
public:
    GitManager();
    ~GitManager();
    
    METHOD_LIST_BEGIN
        METHOD_ADD(GitManager::clone, "/clone", drogon::Post);
        METHOD_ADD(GitManager::commit, "/commit", drogon::Post);
        METHOD_ADD(GitManager::status, "/status", drogon::Get);
    METHOD_LIST_END
    
    void clone(const drogon::HttpRequestPtr& req,
               std::function<void(const drogon::HttpResponsePtr&)>&& callback);
               
    void commit(const drogon::HttpRequestPtr& req,
                std::function<void(const drogon::HttpResponsePtr&)>&& callback);
                
    void status(const drogon::HttpRequestPtr& req,
                std::function<void(const drogon::HttpResponsePtr&)>&& callback);

private:
    std::string repo_base_path_ = "/d/vc/repositories";
    git_repository* openRepository(const std::string& project_id);
};
